package cn.gailvlun.gll.presentation.login.adapter;

import android.content.Context;

import com.github.markzhai.recyclerview.MultiTypeAdapter;

import cn.gailvlun.gll.R;
import cn.gailvlun.gll.presentation.login.bean.CountryCode;



public class SelectCountryCodeAdapter extends MultiTypeAdapter {

    public enum Type {
        HEADER, COUNTRY
    }

    public SelectCountryCodeAdapter(Context context) {
        super(context);

        addViewTypeToLayoutMap(Type.HEADER.ordinal(), R.layout.item_country_code_header);
        addViewTypeToLayoutMap(Type.COUNTRY.ordinal(), R.layout.item_country_code_country);
    }

    public int getFirstLetterPosition(char firstLetter) {
        for (int i = 0; i < getItemCount(); i++) {
            if (getItemViewType(i) == Type.HEADER.ordinal() && mCollection.get(i).equals(String.valueOf(firstLetter))) {
                return i;
            }
        }
        return -1;
    }

    public int getCountryCodePosition(String countryCode) {
        for (int i = 0; i < getItemCount(); i++) {
            if (getItemViewType(i) == Type.COUNTRY.ordinal() &&
                    ((CountryCode) mCollection.get(i)).getCountryCode().equals(countryCode)) {
                return i;
            }
        }
        return -1;
    }
}
